/*
 *  serveur.h
 *  pire2pireV1
 *
 *  Created by jihed kamkoum on 04/05/10.
 *  Copyright 2010 ENSEIRB. All rights reserved.
 *
 */
#ifndef SERVEUR_H_
#define SERVEUR_H_
#include "cmd_handler.h"


typedef struct _binder{
	SOCKET * sock;
	char ** ip;
	int * port;
	int semid;
	clientlist_t ** listeClients;
	filelist_t ** listeFichiers;
	int fdpipe1;
	int fdpipe0;
	int fdpipes1;
	int fdpipes0;
	char ** path;
	ListeUpload ** listeUpload;
	ListeDownload ** listeDownload;
	pthread_mutex_t *downloadTableAccess;
	pthread_mutex_t *uploadTableAccess;
	pthread_mutex_t *fileTableAccess;
	pthread_mutex_t *clientTableAccess;
	pthread_mutex_t *clientSocketAccess;
	pthread_mutex_t *socketAccess;
	pthread_mutex_t * neighbourhoodCondMutex;
	pthread_cond_t * neighbourhoodCond;
	int  * neighbourhoodbool;
	pthread_mutex_t * listCondMutex;
	pthread_cond_t * listCond;
	int  * listbool;
	pthread_mutex_t * trafficCondMutex;
	pthread_cond_t * trafficCond;
	int  * trafficbool;
	int * csock;
}binder;


/*
 *Configuration de laserveur/serveur.c socket serveur
 */
void bind_serveur(binder *b);
/*
 * Traitement des requêtes clients.
 */
void deal_with_data(int listnum,int * connectlist,binder *b);
/*
 *thread permettant le traitement des requêtes clients
 */
void * f_thread_serveur(cmdrecv * recived);
/*
 *Accepte les nouvelles connections des clients.
 *Vérifie les requêtes clients
 */
void read_socks(fd_set *socks,int * connectlist,binder * b);
/*
 *Accepte les nouvelles connections
 */
void handle_new_connection(int sock,int *connectlist,clientlist_t * listeClients,pthread_mutex_t *clientTableAccess);
/*
 *La construction du buffer contenant les sockets
 */
void build_select_list(int sock,fd_set* socks,int * connectlist,int* highsock ,int fdpipe);
/*
 *Modifie le flag du descripteur en mode non bloquant
 */
void setnonblocking(int sock);


#endif /*SERVEUR_H_*/
